package com.example.javaeeblog20240514.demos;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/demo")
public class Demo {
    @RequestMapping("/r1")
    public String r1(){
        return "/index.html";
    }

    @ResponseBody
    @RequestMapping("/r2")
    public String r2(){
        return "<h1>.....</h1>";
    }
    @ResponseBody
    @RequestMapping("/r3")
    public User r3(){
        User user = new User();
        user.setName("zhangsan");
        user.setAge(18);
        user.setSex("男");
        return user;
    }
    @ResponseBody
    @RequestMapping("/r4")
    public Map<String, String> r4(){
        HashMap map = new HashMap();
        map.put("key", "value");
        map.put("zhangsan", "lisi");
        return map;
    }
    @ResponseBody
    @RequestMapping("/r5")
    public String r5(){
        return "/a.js";
    }

    @ResponseBody
    @RequestMapping("/r6")
    public String r6(){
        return "/b.css";
    }

    @ResponseBody
    @RequestMapping("/r7")
    public String r7(HttpServletResponse response){
        response.setStatus(404);
        return "设置成功";
    }

    @ResponseBody
    @RequestMapping("/r8")
    public String r8(HttpServletResponse response){
        response.setStatus(404);
        return "设置成功";
    }
    @ResponseBody
    @RequestMapping(value = "/r9",produces = "application/json")
    public String r9(){
        return "1111";
    }

    @ResponseBody
    @RequestMapping("/r10")
    public String r10(HttpServletResponse response) {
        List<Integer> list = new ArrayList<>();

        response.setHeader("key","value");
        return "设置成功";
    }
}
